package projectx.util;

public class MathUtil {
	// --------------------------------------------------------------------------
	// S T A T I C M E N B E R S
	//
	// --------------------------------------------------------------------------

	public static final double TEN = 10.0;

	public static final double HALF = 0.5;

	// --------------------------------------------------------------------------
	// C O N S T R U C T O R S
	//
	// --------------------------------------------------------------------------
	private MathUtil() {
		super();
	}

	// --------------------------------------------------------------------------
	// S T A T I C M E T H O D S
	//
	// --------------------------------------------------------------------------

	public static double round(double dVal, double dSyou) {

		double dTempVal;
		double dOutVal;

		dTempVal = Math.abs(dVal) + (double) (HALF / Math.pow(TEN, dSyou));

		dOutVal = floor(dTempVal * Math.pow(TEN, dSyou)) / Math.pow(TEN, dSyou);

		if (dVal < 0) {
			return (-dOutVal);
		} else {
			return (dOutVal);
		}
	}

	public static double rint(double dVal, double dSyou) {

		double dOutVal;

		double dPow = Math.pow(TEN, dSyou);

		dOutVal = Math.rint(dVal * dPow) / dPow;

		return dOutVal;

	}

	public static int floor(double value) {
		return new Double(value).intValue();
	}
}
